package com.frxuexi.mdm2205.demo

import android.widget.CheckBox
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DatePickerDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.mdm2205.R
import java.text.SimpleDateFormat

@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Preview
@Composable
fun Demo07() {
    var isShow by remember {
        mutableStateOf(false)
    }
    Scaffold(floatingActionButton = {
        FloatingActionButton(onClick = { ToastUtils.showLong("悬浮") },shape= CircleShape) {
            Icon(imageVector = Icons.Default.Add, contentDescription = "")
        }
    }) {
        Column(
            Modifier
                .padding(it)
                .padding(10.dp)) {
            Card(modifier = Modifier
                .fillMaxWidth(), colors = CardDefaults.cardColors(containerColor= Color.White), border = BorderStroke(1.dp,Color.DarkGray) ) {
                Row(modifier = Modifier
                    .fillMaxWidth()
                    .padding(10.dp)) {
                    Image(painter = painterResource(id = R.drawable.ic_launcher_background), contentDescription = "")
                    Text(text = "标题")
                }

            }
            Button(onClick = { isShow=true }) {
                Text(text = "进度")
            }
            if(isShow){
                CircularProgressIndicator()
                LinearProgressIndicator()
            }

            var checked by remember {
                mutableStateOf(false)
            }
           /* var checked2 by remember {
                mutableStateOf(false)
            }*/

            var check by remember {
                mutableStateOf(0)
            }
            Row (verticalAlignment = Alignment.CenterVertically){
                Checkbox(checked = check==1, onCheckedChange = {
                    if(it)
                        check=1
                })
                Text(text = "男")
                Spacer(modifier = Modifier.width(20.dp))
                Checkbox(checked = check==2, onCheckedChange = {
                    check=2
                })
                Text(text = "女")
            }

            var radio by remember {
                mutableStateOf(false)
            }
            RadioButton(selected = radio, onClick = { radio=!radio })


            var isShowDate by remember {
                mutableStateOf(false)
            }

            val pickerState = rememberDatePickerState()
            var time by remember {
                mutableStateOf( SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis()))
            }
            /*Button(onClick = { isShowDate=true }) {
                Text(text = "日期")
            }*/
            OutlinedTextField(value = time, onValueChange = {}, readOnly = true,
                trailingIcon={ Icon(imageVector = Icons.Default.DateRange, contentDescription = "",Modifier.clickable {
                    isShowDate=true
                })})

            if(isShowDate){
                DatePickerDialog(onDismissRequest = { isShowDate=false }, confirmButton = {
                    Text(text = "OK",Modifier.clickable {
                        time =
                            SimpleDateFormat("yyyy-MM-dd").format(pickerState.selectedDateMillis)

                        isShowDate=false
                    })
                }) {
                    DatePicker(state = pickerState)
                }
            }
        }
    }
}